<html>
<body>

<?php 

$taxonomy_file = "taxonomy.txt";
$assistance_file = "assistance.txt";
$contacted_file = "contacted.txt";
$time_file = "time.txt";
$treated_file = "treated.txt";
$unreachable_file = "unreachable.txt";
$refer_file = "refer.txt";
$config_file = "config.txt";
$max_runtime = 6000;


echo "Maximum script runtime set to ".$max_runtime." seconds.<BR>";
set_time_limit($max_runtime);
error_reporting('IGNORE_REPEATED_ERRORS');

$conn = mysql_connect ("localhost", "root", "") or die ('Error: ' . mysql_error());
$db = mysql_select_db("QA");


$handle = @fopen($taxonomy_file, "r");
echo "Taxonomy file opened: ".$taxonomy_file." with handle ".$handle."<BR>";
if ($handle) {
        $source = null;
        $buftok[] = null;
	while (!feof($handle)){
		$bufferin = fgets($handle);
                $bufferin = trim($bufferin);
                if(strlen(trim($bufferin))>0){
                    $query_string = "SELECT Taxonomy_Description FROM QA.Taxonomies WHERE Taxonomy_Description LIKE \"".mysql_real_escape_string($bufferin)."\";";
                    $select_results = mysql_query($query_string);
                    if(!mysql_result($select_results,0)){
                         $query_string = "INSERT INTO QA.Taxonomies (Taxonomy_Description) VALUES (\"".mysql_real_escape_string($bufferin)."\");";
                         $insert_results = mysql_query($query_string);
                    }
                }
	}

     fclose($handle);   
}



$handle = @fopen($assistance_file, "r");
echo "Assistance file opened: ".$assistance_file." with handle ".$handle."<BR>";
if ($handle) {
        $source = null;
        $buftok[] = null;
	while (!feof($handle)){
		$bufferin = fgets($handle);
                $bufferin = trim($bufferin);
                if(strlen(trim($bufferin))>0){
                    $query_string = "SELECT Assistance_Description FROM QA.Assistance WHERE Assistance_Description LIKE \"".mysql_real_escape_string($bufferin)."\";";
                    $select_results = mysql_query($query_string);
                    if(!mysql_result($select_results,0)){
                         $query_string = "INSERT INTO QA.Assistance (Assistance_Description) VALUES (\"".mysql_real_escape_string($bufferin)."\");";
                         $insert_results = mysql_query($query_string);
                    }
                }
	}

     fclose($handle);   
}



$handle = @fopen($contacted_file, "r");
echo "Contacted file opened: ".$contacted_file." with handle ".$handle."<BR>";
if ($handle) {
        $source = null;
        $buftok[] = null;
	while (!feof($handle)){
		$bufferin = fgets($handle);
                $bufferin = trim($bufferin);
                if(strlen(trim($bufferin))>0){
                    $query_string = "SELECT Contacted_Description FROM QA.Contacted WHERE Contacted_Description LIKE \"".mysql_real_escape_string($bufferin)."\";";
                    $select_results = mysql_query($query_string);
                    if(!mysql_result($select_results,0)){
                         $query_string = "INSERT INTO QA.Contacted (Contacted_Description) VALUES (\"".mysql_real_escape_string($bufferin)."\");";
                         $insert_results = mysql_query($query_string);
                    }
                }
	}

     fclose($handle);   
}


$handle = @fopen($time_file, "r");
echo "Time file opened: ".$time_file." with handle ".$handle."<BR>";
if ($handle) {
        $source = null;
        $buftok[] = null;
	while (!feof($handle)){
		$bufferin = fgets($handle);
                $bufferin = trim($bufferin);
                if(strlen(trim($bufferin))>0){
                    $query_string = "SELECT Time_Description FROM QA.Time WHERE Time_Description LIKE \"".mysql_real_escape_string($bufferin)."\";";
                    $select_results = mysql_query($query_string);
                    if(!mysql_result($select_results,0)){
                         $query_string = "INSERT INTO QA.Time (Time_Description) VALUES (\"".mysql_real_escape_string($bufferin)."\");";
                         $insert_results = mysql_query($query_string);
                    }
                }
	}

     fclose($handle);   
}



$handle = @fopen($treated_file, "r");
echo "Treated file opened: ".$treated_file." with handle ".$handle."<BR>";
if ($handle) {
        $source = null;
        $buftok[] = null;
	while (!feof($handle)){
		$bufferin = fgets($handle);
                $bufferin = trim($bufferin);
                if(strlen(trim($bufferin))>0){
                    $query_string = "SELECT Treated_Description FROM QA.Treated WHERE Treated_Description LIKE \"".mysql_real_escape_string($bufferin)."\";";
                    $select_results = mysql_query($query_string);
                    if(!mysql_result($select_results,0)){
                         $query_string = "INSERT INTO QA.Treated (Treated_Description) VALUES (\"".mysql_real_escape_string($bufferin)."\");";
                         $insert_results = mysql_query($query_string);
                    }
                }
	}

     fclose($handle);   
}




$handle = @fopen($unreachable_file, "r");
echo "Unreachable file opened: ".$unreachable_file." with handle ".$handle."<BR>";
if ($handle) {
        $source = null;
        $buftok[] = null;
	while (!feof($handle)){
		$bufferin = fgets($handle);
                $bufferin = trim($bufferin);
                if(strlen(trim($bufferin))>0){
                    $query_string = "SELECT Reason_Description FROM QA.Unreachable_Reasons WHERE Reason_Description LIKE \"".mysql_real_escape_string($bufferin)."\";";
                    $select_results = mysql_query($query_string);
                    if(!mysql_result($select_results,0)){
                         $query_string = "INSERT INTO QA.Unreachable_Reasons (Reason_Description) VALUES (\"".mysql_real_escape_string($bufferin)."\");";
                         $insert_results = mysql_query($query_string);
                    }
                }
	}

     fclose($handle);   
}

$handle = @fopen($refer_file, "r");
echo "Refer file opened: ".$refer_file." with handle ".$handle."<BR>";
if ($handle) {
        $source = null;
        $buftok[] = null;
	while (!feof($handle)){
		$bufferin = fgets($handle);
                $bufferin = trim($bufferin);
                if(strlen(trim($bufferin))>0){
                    $query_string = "SELECT Refer_Description FROM QA.Refer WHERE Refer_Description LIKE \"".mysql_real_escape_string($bufferin)."\";";
                    $select_results = mysql_query($query_string);
                    if(!mysql_result($select_results,0)){
                         $query_string = "INSERT INTO QA.Refer (Refer_Description) VALUES (\"".mysql_real_escape_string($bufferin)."\");";
                         $insert_results = mysql_query($query_string);
                    }
                }
	}

     fclose($handle);   
}





$handle = @fopen($config_file, "r");
echo "Config file opened: ".$config_file." with handle ".$handle."<BR>";
if ($handle) {
	//echo "Reading File<BR>";
        $source = null;
        $buftok[] = null;
	while (!feof($handle)){
		$bufferin = fgets($handle);
                $bufferin = trim($bufferin);
                if(strlen(trim($bufferin))>0){
	            //echo "Line Buff: $bufferin<BR>";
		    $line = explode(",",$bufferin);
                    $query_string = "SELECT Short_Description FROM QA.Config WHERE Short_Description LIKE \"".mysql_real_escape_string(trim($line[0]))."\";";
		    //echo "SQL: $query_string<BR>";
                    $select_results = mysql_query($query_string);
                    if(!mysql_result($select_results,0)){
                         $query_string = "INSERT INTO QA.Config (Short_Description, Long_Description, Help_URL, Value) VALUES (\"".mysql_real_escape_string(trim($line[0]))."\", \"".mysql_real_escape_string(trim($line[1]))."\", \"".mysql_real_escape_string(trim($line[2]))."\", \"".mysql_real_escape_string(trim($line[3]))."\");";
                         $insert_results = mysql_query($query_string);
                    }
                }
	}

     fclose($handle);   
}


?><BR>

</body>
</html>